package cn.edu.cqyz.wisdom.service.impl;

import cn.edu.cqyz.wisdom.entity.R;
import cn.edu.cqyz.wisdom.entity.SessionQa;
import cn.edu.cqyz.wisdom.mapper.SessionQaMapper;
import cn.edu.cqyz.wisdom.service.AiKimiService;
import cn.edu.cqyz.wisdom.service.ISessionQaService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 会话问题表 服务实现类
 * </p>
 *
 * @author CDHong.it
 * @since 2024-12-18
 */
@Service
public class SessionQaServiceImpl extends ServiceImpl<SessionQaMapper, SessionQa> implements ISessionQaService {

    @Autowired
    public SessionQaMapper sessionQaMapper;


    /**
     * 加入问题/回答
     * */
    @Override
    public R installSessionQa(SessionQa sessionQa){
        SessionQa newSessionQa = new SessionQa();
        newSessionQa.setUserId(sessionQa.getUserId());
        newSessionQa.setSessionId(sessionQa.getSessionId());
        newSessionQa.setProblemContent(sessionQa.getProblemContent());
        newSessionQa.setAnswerContent(sessionQa.getAnswerContent());
        try{
            sessionQaMapper.insert(newSessionQa);
            return R.ok("成功!");
        }catch (Exception e){
            e.printStackTrace();
            return R.error("失败!");
        }
    }

    /**
     * 获取问答
     * */
    @Override
    public List<SessionQa> findAllSessionQa(Integer sessionId){
        QueryWrapper<SessionQa> wrapper = new QueryWrapper<>();
        wrapper.eq("session_id",sessionId);
        return sessionQaMapper.selectList(wrapper);
    }

}
